﻿using System;

// 定义形状接口
public interface IShape
{
    double CalculateArea();
}

// 实现圆形类
public class Circle : IShape
{
    private double radius;

    public Circle(double radius)
    {
        this.radius = radius;
    }

    public double CalculateArea()
    {
        return Math.PI * radius * radius;
    }
}

// 实现正方形类
public class Square : IShape
{
    private double side;

    public Square(double side)
    {
        this.side = side;
    }

    public double CalculateArea()
    {
        return side * side;
    }
}

// 创建简单工厂类
public static class ShapeFactory
{
    public static IShape CreateShape(string shapeType, double dimension)
    {
        switch (shapeType)
        {
            case "circle":
                return new Circle(dimension);
            case "square":
                return new Square(dimension);
            default:
                throw new ArgumentException("Invalid shape type");
        }
    }
}

// 主程序
class Program
{
    static void Main()
    {
        Random random = new Random();
        double totalArea = 0;

        for (int i = 0; i < 10; i++)
        {
            string shapeType = random.Next(2) == 0 ? "circle" : "square";
            double dimension = random.NextDouble() * 10; // 随机生成0到10之间的数
            IShape shape = ShapeFactory.CreateShape(shapeType, dimension);
            totalArea += shape.CalculateArea();
            Console.WriteLine($"Shape: {shapeType}, Dimension: {dimension}, Area: {shape.CalculateArea()}");
        }

        Console.WriteLine($"Total Area: {totalArea}");
    }
}